package com.nemlistapp;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.widget.EditText;

public class BoughtFetcher extends AsyncTask<Integer, Void, Void> {
	
	private String NAMESPACE;
	
	private final String METHOD_NAME = "MarkAsBought";
	private final String SOAP_ACTION = "http://tempuri.org/IListService/MarkAsBought";
	
	private String URL;
	private SoapSerializationEnvelope envelope;
	private Context context;

	
	public BoughtFetcher(Context context){
		
		this.context = context;

	}

	@Override
	protected Void doInBackground(Integer...params) {
		
		int shoppingListId = params[0];
		int productId = params[1];
		
		NAMESPACE = context.getString(R.string.ws_namespace);
		URL = context.getString(R.string.ws_url);
		
		SoapObject request  = new SoapObject(NAMESPACE,METHOD_NAME);
		
		PropertyInfo shoppingListIdProperty = new PropertyInfo();
		PropertyInfo productIdProperty = new PropertyInfo();
		
		shoppingListIdProperty.setName("shoppingListId");
		shoppingListIdProperty.setValue(shoppingListId);
		shoppingListIdProperty.setType(Integer.class);
		
		productIdProperty.setName("productId");
		productIdProperty.setValue(productId);
		productIdProperty.setType(Integer.class);
		
		request.addProperty(shoppingListIdProperty);
		request.addProperty(productIdProperty);
		
		envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.implicitTypes = true;
		envelope.setOutputSoapObject(request);
		
		HttpTransportSE httpRequest = new HttpTransportSE(URL);
		
		try{
			
			httpRequest.call(SOAP_ACTION, envelope);
			SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
			
		} catch (Exception e){
			e.printStackTrace();
		}
		return null;
	}

}
